<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

	<xsl:param name="unit"/>
	<xsl:param name="date"/>
	<xsl:param name="photoWidth" select="'48mm'"/>
	<xsl:variable name="textHeight" select="'10mm'"/>

	<xsl:template match="/">
		<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xhtml="http://www.w3.org/1999/xhtml">
			<fo:layout-master-set>
				<fo:simple-page-master master-name="titlePage" page-width="11in" page-height="8.5in">
					<fo:region-body margin-top="0.5in" margin-bottom="1in" margin-left="0.5in" margin-right="0.5in" />
				</fo:simple-page-master>
				<fo:simple-page-master master-name="contentPages" page-width="11in" page-height="8.5in">
					<fo:region-body margin-top="0.5in" margin-bottom="0.5in" margin-left="0.5in" margin-right="0.5in"/>
					<fo:region-before region-name="contentHeader" extent="0.4in" />
					<fo:region-after region-name="contentFooter" extent="0.4in" />
				</fo:simple-page-master>
			</fo:layout-master-set>

			<fo:page-sequence master-reference="contentPages" initial-page-number="1" format="1">
				<fo:static-content flow-name="contentHeader">
					<fo:block display-align="after" text-align="center">
						<xsl:value-of select="$unit"/>
					</fo:block>
					<fo:block display-align="after" text-align="center">
						<xsl:value-of select="$date"/>
					</fo:block>
				</fo:static-content>
				<fo:static-content flow-name="contentFooter">
					<fo:block text-align="center">For church use only</fo:block>
					<fo:block text-align="center">
						Page <fo:page-number />
					</fo:block>
				</fo:static-content>
				<fo:flow font-family="Times New Roman, serif" font-size="8pt" flow-name="xsl-region-body">

					<xsl:apply-templates select="families"/>

				</fo:flow>
			</fo:page-sequence>

		</fo:root>
	</xsl:template>

	<xsl:template match="families">
		<xsl:apply-templates select="family[@photo]"/>
	</xsl:template>

	<xsl:attribute-set name="familyName">
		<xsl:attribute name="font-family">Verdana</xsl:attribute>
		<xsl:attribute name="font-size">
			<xsl:value-of select="$textHeight"/>
		</xsl:attribute>
		<xsl:attribute name="text-align">center</xsl:attribute>
		<xsl:attribute name="color">red</xsl:attribute>
		<xsl:attribute name="width">4in</xsl:attribute>
	</xsl:attribute-set>

	<xsl:template match="family">
		<fo:block width="{$photoWidth}">
			<fo:external-graphic src="url({@photo})"
										width="{$photoWidth}" content-width="{$photoWidth}" />
			<fo:block xsl:use-attribute-sets="familyName" border-width="1mm">
				<!-- first names -->
				<xsl:for-each select="member">
					<fo:inline>
						<xsl:if test="@dependent = 'False'">
							<xsl:attribute name="font-weight">bold</xsl:attribute>
						</xsl:if>
						<xsl:value-of select="@name"/>
					</fo:inline>
					<xsl:if test="position() &lt; last() and last() > 2">
						<xsl:text>, </xsl:text>
					</xsl:if>
					<xsl:if test="position() = last() - 1">
						<xsl:text> and </xsl:text>
					</xsl:if>
				</xsl:for-each>

				<!-- last name -->
				<xsl:text> </xsl:text>
				<xsl:value-of select="@surname"/>
			</fo:block>
		</fo:block>
	</xsl:template>
</xsl:stylesheet>
